home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*************************************************************************
- * $Date: 1992/11/23 18:01:54 $
- * $Revision: 1.3 $
- *
- * Copyright (c) 1991, Visual Edge Software Ltd.
- * ---------------------------------------------
- * ALL RIGHTS RESERVED. This notice is intended as a precaution
- * against inadvertent publication, and shall not be deemed to
- * constitute an acknowledgment that publication has occurred nor to
- * imply any waiver of confidentiality. The year included in the
- * notice is the year of the creation of the work.
- *------------------------------------------------------------------------
- * UxXt.c
- *------------------------------------------------------------------------*/
-
- #include <stdio.h>
-
- #include <X11/Intrinsic.h>
- #include <X11/Shell.h>
- #include <X11/StringDefs.h>
- #include <X11/Xutil.h>
- #include <X11/X.h>
- #include <X11/Xmd.h>
- #include <X11/Xlib.h>
- #include <Xm/Xm.h>
- #include <Xm/DialogS.h>
-
- #include "UxXt.h"
- #ifdef DEBUG
- #include <malloc.h>
- #endif
-
- static XContext xcontext_id = NULL;
-
- /******************************************************************************
- NAME: GetTrueToplevel( wgt )
-
- INPUT: Widget wgt - the top user-created widget
-
- RETURN: Widget - the shell widget
-
- DESCRIPTION: Returns the true toplevel of that interface.
- This is needed for implicit shells where the widget passed to
- one of the Ux functions is not always the shell.
-
- CREATION: Visual Edge Software April 6 1991
- -----------------------------------------------------------------------------*/
- #ifdef _NO_PROTO
- static Widget GetTrueToplevel( wgt )
- Widget wgt;
- #else
- static Widget GetTrueToplevel( Widget wgt )
- #endif
- {
- if (wgt && !XtIsShell(wgt))
- {
- wgt = XtParent(wgt);
- }
- return wgt;
- }
-
- /******************************************************************************
- NAME: handle_dialog_child( wgt, manage_func )
-
- INPUT: Widget wgt - the dialogShellWidget
- void (*manage_func)() - either XtManageChild
- or XtUnmanageChild
-
- RETURN: int - UX_NO_ERROR if successfull
- UX_ERROR otherwise
-
- DESCRIPTION: Handles the popping up or popping down of dialog shells
- by managing or unmanaging their children.
-
- CREATION: Visual Edge Software Sept 19/91
- -----------------------------------------------------------------------------*/
- #ifdef _NO_PROTO
- static int handle_dialog_child( wgt, manage_func )
- Widget wgt;
- void (*manage_func)();
- #else
- static int handle_dialog_child( Widget wgt, void (*manage_func)() )
- #endif
- {
- int i, num_children;
- Widget *children;
-
- XtVaGetValues( wgt,
- XmNnumChildren, &num_children,
- XmNchildren, &children,
- NULL );
-
- /* We manage/unmanage the first rectObj child in the list.
- * Note that the check for rectObjClass is necessary since some
- * implementations of Motif add protocol children to the dialogShell.
- */
-
- for (i = 0; i < num_children; i++)
- {
- if ( XtIsSubclass( children[i], rectObjClass ) )
- {
- (*manage_func)(children[i]);
- return ( UX_NO_ERROR );
- }
- }
-
- return ( UX_ERROR );
- }
-
- /******************************************************************************
- NAME: popup_dialog( wgt, grab_flag )
-
- INPUT: Widget wgt - dialogShell to pop up
- XtGrabKind grab_flag - the grab flag
-
- RETURN: void
-
- DESCRIPTION: Pops up a dialogShell.
-
- CREATION: Visual Edge Software Sept 19/91
- -----------------------------------------------------------------------------*/
- #ifdef _NO_PROTO
- static void popup_dialog( wgt, grab_flag )
- Widget wgt;
- XtGrabKind grab_flag;
- #else
- static void popup_dialog( Widget wgt, XtGrabKind grab_flag )
- #endif
- {
- if ( handle_dialog_child( wgt, XtManageChild ) == UX_ERROR )
- XtPopup( wgt, grab_flag );
- }
-
- /******************************************************************************
- NAME: UxPopupInterface( wgt, grab_flag )
-
- INPUT: Widget wgt - Widget to popup
- XtGrabKind grab_flag - grab flag
-
- RETURN: int UX_ERROR or UX_NO_ERROR
-
- DESCRIPTION: Popups up an interface. The widget should be a toplevel widget.
- Note that special handling is required for dialogShells since
- those are popped up by managing their children if they have
- some.
- The grab_flag could be any of:
- no_grab (XtGrabNone)
- nonexclusive_grab (XtGrabNonexclusive)
- exclusive_grab (XtGrabExclusive)
-
- CREATION: Visual Edge Software April 6 1991
- -----------------------------------------------------------------------------*/
- #ifdef _NO_PROTO
- int UxPopupInterface( wgt, grab_flag )
- Widget wgt;
- XtGrabKind grab_flag;
- #else
- int UxPopupInterface( Widget wgt, XtGrabKind grab_flag )
- #endif
- {
- if (!(wgt = GetTrueToplevel(wgt)))
- return ( UX_ERROR );
-
- if ( XtIsSubclass( wgt, xmDialogShellWidgetClass ) )
- {
- popup_dialog( wgt, grab_flag );
- }
- else
- {
- XtPopup( wgt, grab_flag );
- }
-
- return ( UX_NO_ERROR );
- }
-
- /******************************************************************************
- NAME: popdown_dialog( wgt )
-
- INPUT: Widget wgt - dialogShell to popdown
-
- RETURN: void
-
- DESCRIPTION: Pops down a dialogShell.
-
- CREATION: Visual Edge Software Sept 19/91
- -----------------------------------------------------------------------------*/
- #ifdef _NO_PROTO
- static void popdown_dialog( wgt )
- Widget wgt;
- #else
- static void popdown_dialog( Widget wgt )
- #endif
- {
- if ( handle_dialog_child( wgt, XtUnmanageChild ) == UX_ERROR )
- XtPopdown( wgt );
- }
-
- /******************************************************************************
- NAME: UxPopdownInterface( wgt )
-
- INPUT: Widget wgt - Widget to popdown
-
- RETURN: int UX_ERROR / UX_NO_ERROR
-
- DESCRIPTION: Pops down an interface. The widget should be a toplevel widget.
- Note that special handling is required for dialogShells since
- those are popped down by unmanaging their children if they have
- some.
-
- CREATION: Visual Edge Software April 6 1991
- -----------------------------------------------------------------------------*/
- #ifdef _NO_PROTO
- int UxPopdownInterface( wgt )
- Widget wgt;
- #else
- int UxPopdownInterface( Widget wgt )
- #endif
- {
- if (!(wgt = GetTrueToplevel(wgt)))
- return ( UX_ERROR );
-
- if ( XtIsSubclass( wgt, xmDialogShellWidgetClass ) )
- {
- popdown_dialog( wgt );
- }
- else
- {
- XtPopdown( wgt );
- }
-
- return ( UX_NO_ERROR );
- }
-
- /******************************************************************************
- NAME: UxDestroyInterface( wgt )
-
- INPUT: Widget wgt - Widget to destroy
-
- RETURN: int UX_ERROR / UX_NO_ERROR
-
- DESCRIPTION: Destroys an interface. The widget should be a toplevel widget.
-
- CREATION: Visual Edge Software April 6 1991
- -----------------------------------------------------------------------------*/
- #ifdef _NO_PROTO
- int UxDestroyInterface( wgt )
- Widget wgt;
- #else
- int UxDestroyInterface( Widget wgt )
- #endif
- {
- if (!(wgt = GetTrueToplevel(wgt)))
- return ( UX_ERROR );
-
- XtDestroyWidget (wgt);
-
- return ( UX_NO_ERROR );
- }
-
- /******************************************************************************
- NAME: DeleteContextCB( wgt, client_data, call_data )
-
- INPUT: Widget wgt - widget causing the callback
- XtPointer client_data - not used
- XtPointer call_data - not used
-
- RETURN: void
-
- DESCRIPTION: Deletes the X context entry.
-
- EXT REFERENCES: UxTopLevel, xcontext_id
-
- CREATION: Visual Edge Software April 6 1991
- -----------------------------------------------------------------------------*/
- #ifdef _NO_PROTO
- static void DeleteContextCB( wgt, client_data, call_data )
- Widget wgt;
- XtPointer client_data, call_data;
- #else
- static void DeleteContextCB( Widget wgt, XtPointer client_data,
- XtPointer call_data )
- #endif
- {
- (void) XDeleteContext( XtDisplay( DBtoplevel ),
- (Window) wgt,
- xcontext_id );
- }
-
- /******************************************************************************
- NAME: UxPutContext( wgt, context )
-
- INPUT: Widget wgt - Widget
- caddr_t context - context pointer
-
- RETURN: int UX_ERROR / UX_NO_ERROR
-
- DESCRIPTION: Uses the X Context manager to store the given context pointer
- in a memory location that is indexed by the given widget id.
- Also adds a destroyCallback to delete that context when the
- widget is destroyed.
-
- EXT REFERENCES: UxTopLevel, xcontext_id
- EXT EFFECTS: xcontext_id
-
- CREATION: Visual Edge Software April 6 1991
- -----------------------------------------------------------------------------*/
- #ifdef _NO_PROTO
- int UxPutContext( wgt, context )
- Widget wgt;
- caddr_t context;
- #else
- int UxPutContext( Widget wgt, caddr_t context )
- #endif
- {
- int status;
-
- if ( xcontext_id == NULL )
- xcontext_id = XUniqueContext();
-
- if ( wgt == NULL )
- return ( UX_ERROR );
-
- status = XSaveContext( XtDisplay( DBtoplevel ),
- (Window) wgt,
- xcontext_id,
- context );
- if ( status != 0 )
- return ( UX_ERROR );
-
- XtAddCallback (wgt, XmNdestroyCallback, DeleteContextCB, NULL);
-
- return ( UX_NO_ERROR );
- }
-
- /******************************************************************************
- NAME: UxGetContext( wgt )
-
- INPUT: Widget wgt - widget
-
- RETURN: caddr_t - the context pointer
-
- DESCRIPTION: Uses the X Context manager to find the context pointer
- stored in a memory location indexed by the given widget id.
-
- EXT REFERENCES: UxTopLevel, xcontext_id
-
- CREATION: Visual Edge Software April 6 1991
- -----------------------------------------------------------------------------*/
- #ifdef _NO_PROTO
- caddr_t UxGetContext( wgt )
- Widget wgt;
- #else
- caddr_t UxGetContext( Widget wgt )
- #endif
- {
- int status;
- caddr_t context;
-
- if ( wgt == NULL )
- return ( (caddr_t) NULL );
-
- status = XFindContext( XtDisplay( DBtoplevel ),
- (Window) wgt,
- xcontext_id,
- &context );
-
- if ( status != 0 )
- return ( (caddr_t) NULL );
-
- return ( context );
- }
-
- /******************************************************************************
- NAME: UxFreeClientDataCB( wgt, client_data, call_data )
-
- INPUT: Widget wgt - widget
- XtPointer client_data - pointer to be freed
- XtPointer call_data - not used
-
- RETURN: void
-
- DESCRIPTION: This callback function simply frees the client data.
-
- CREATION: Visual Edge Software April 6 1991
- -----------------------------------------------------------------------------*/
- #ifdef _NO_PROTO
- void UxFreeClientDataCB( wgt, client_data, call_data )
- Widget wgt;
- XtPointer client_data, call_data;
- #else
- void UxFreeClientDataCB( Widget wgt, XtPointer client_data,
- XtPointer call_data )
- #endif
- {
- if (client_data != NULL)
- XtFree(client_data);
- }
-
- /******************************************************************************
- NAME: UxLoadResources( fname )
-
- INPUT: char *fname - name of resource file
-
- RETURN: void
-
- DESCRIPTION: This function is provided as a stub function to load the
- resource file that was generated by the C Code Generator
- into the current toolkit resource database.
- A call to this function is automatically generated with the
- appropriate resource filename when resources are set to Public.
-
- CREATION: Visual Edge Software April 6 1991
- -----------------------------------------------------------------------------*/
- #ifdef _NO_PROTO
- void UxLoadResources( fname )
- char *fname;
- #else
- void UxLoadResources( char *fname )
- #endif
- {
- }
-
- void UxNotify()
- {
- UxNotifyFlag = False;
- }
-
- void UxWaitForNotify()
- {
- XEvent event;
- UxNotifyFlag = True;
- while (UxNotifyFlag) {
- XtAppNextEvent(DBapp_context, &event);
- XtDispatchEvent(&event);
- /* printf ("UxNotifyFlag = %d\n", UxNotifyFlag); */
- }
- }
- /***END*OF*FILE****************************************************************/
-
-